/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MantRoles.java
 *
 * Created on 02/10/2011, 12:39:43 AM
 */

package GUI.AdministracionUsuarios;

import BE.FuncionalidadXPerfil;
import BE.FuncionalidadXPerfilId;
import BE.Perfil;
import BE.Permisos;
import BL.PerfilBl;
import GUI.Principal;
import javax.swing.JOptionPane;

/**
 *
 * @author CarLita
 */
public class CreacionPerfiles extends javax.swing.JPanel {
    Perfil perfil;
    private Principal ventanaPrincipal;
    int modoVentana;
    Permisos permisos;
    
    /** Creates new form MantRoles */
    public CreacionPerfiles() {
        initComponents();
        modoVentana = Principal.MODO_CREACION;        
        setearModo();
        bloquearPorPermisos();
    }
    
    public CreacionPerfiles(Principal ventanaPrincipal) {
        initComponents();
        this.ventanaPrincipal = ventanaPrincipal;        
        modoVentana = Principal.MODO_CREACION;
        setearModo();
        bloquearPorPermisos();
    }
    
    public CreacionPerfiles(Perfil perfil, int modoVentana, Permisos permisos){
        initComponents();
        this.perfil = perfil;
        this.modoVentana= modoVentana;
        this.permisos = permisos;
        setearModo();        
    }
    
    private void setearModo(){
        switch(modoVentana){
            case Principal.MODO_CREACION:
                btnEditar.setVisible(false);
                btnGuardar.setVisible(true);
                btnLimpiar.setVisible(true);
                break;
            case Principal.MODO_EDICION:
                llenarInformacion();
                desbloquearCampos(true);
                btnEditar.setVisible(false);
                btnGuardar.setVisible(true);
                btnLimpiar.setVisible(true);
                break;
            case Principal.MODO_LECTURA:
                llenarInformacion();
                desbloquearCampos(false);
                btnEditar.setVisible(true);
                btnGuardar.setVisible(false);
                btnLimpiar.setVisible(false);
                break;            
        }
    }
    
    private void desbloquearCampos(boolean desbloquear){
        txtNombre.setEditable(desbloquear);
        txtDescripcion.setEditable(desbloquear);
        
        chkCompletarPT.setEnabled(desbloquear);
    }
    
    private void llenarInformacion(){
        txtNombre.setText(perfil.getNombre());
        txtDescripcion.setText(perfil.getDescripcion());        
        
        llenarPermisosMarcoReferencia();
        llenarPermisosPapelTrabajo();
        llenarPermisosHallazgo();
        llenarPermisosRecomendacion();
        llenarPermisosUsuario();
        llenarPermisoPerfil();
        llenarPermisoLogs();
        llenarPermisoEstadoPortafolio();
        llenarPermisoProyecto();
    }
    
    private void llenarPermisosMarcoReferencia(){
        chkCrearMarco.setSelected(permisos.getPermisoMarco().indexOf(UtilUsuarios.CREAR) >-1);
        
        
    }
        
    private void llenarPermisosPapelTrabajo(){
        
    }
        
    private void llenarPermisosHallazgo(){
        
    } 
     
    private void llenarPermisosRecomendacion(){
        
    }
        
    private void llenarPermisosUsuario(){
        
    }
        
    private void llenarPermisoPerfil(){
        
    }
        
    private void llenarPermisoLogs(){
        
    }
        
    private void llenarPermisoEstadoPortafolio(){
        
    }
        
    private void llenarPermisoProyecto(){
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        chkCrearMarco = new javax.swing.JCheckBox();
        chkVerMarco = new javax.swing.JCheckBox();
        chkEditarMarco = new javax.swing.JCheckBox();
        jLabel4 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        chkInformeProyecto = new javax.swing.JCheckBox();
        chkCrearProyecto = new javax.swing.JCheckBox();
        chkVerProyecto = new javax.swing.JCheckBox();
        chkEditarProyecto = new javax.swing.JCheckBox();
        jLabel3 = new javax.swing.JLabel();
        chkTerminarProyecto = new javax.swing.JCheckBox();
        jPanel4 = new javax.swing.JPanel();
        chkCrearPT = new javax.swing.JCheckBox();
        chkVerPT = new javax.swing.JCheckBox();
        chkEditarPT = new javax.swing.JCheckBox();
        jLabel6 = new javax.swing.JLabel();
        chkVistaPrePT = new javax.swing.JCheckBox();
        chkCompletarPT = new javax.swing.JCheckBox();
        jPanel5 = new javax.swing.JPanel();
        chkCrearHallazgo = new javax.swing.JCheckBox();
        chkVerHallazgo = new javax.swing.JCheckBox();
        chkEditarHallazgo = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        chkCrearUsuario = new javax.swing.JCheckBox();
        chkVerUsuario = new javax.swing.JCheckBox();
        chkEditarUsuario = new javax.swing.JCheckBox();
        jLabel7 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        chkCrearPerfil = new javax.swing.JCheckBox();
        chkVerPerfil = new javax.swing.JCheckBox();
        chkEditarPerfil = new javax.swing.JCheckBox();
        jLabel8 = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        chkLogs = new javax.swing.JCheckBox();
        chkReportePortafolio = new javax.swing.JCheckBox();
        jLabel9 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        chkCrearRecomendacion = new javax.swing.JCheckBox();
        chkVerRecomendacion = new javax.swing.JCheckBox();
        chkEditarRecomendacion = new javax.swing.JCheckBox();
        jLabel10 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        btnLimpiar = new javax.swing.JButton();
        btnCancelar3 = new javax.swing.JButton();
        btnGuardar = new javax.swing.JButton();
        btnEditar = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        txtDescripcion = new javax.swing.JTextField();

        jLabel1.setText("Nombre:");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Funciones"));

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        chkCrearMarco.setText("Crear");

        chkVerMarco.setText("Ver");

        chkEditarMarco.setText("Editar");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel4.setText("Marco de Referencia");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(chkVerMarco)
                    .addComponent(chkEditarMarco)
                    .addComponent(chkCrearMarco)
                    .addComponent(jLabel4))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkCrearMarco)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkEditarMarco)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkVerMarco)
                .addContainerGap(65, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        chkInformeProyecto.setText("Generar Informe Final");

        chkCrearProyecto.setText("Crear");

        chkVerProyecto.setText("Ver");

        chkEditarProyecto.setText("Editar");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel3.setText("Proyecto");

        chkTerminarProyecto.setText("Terminar");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(chkInformeProyecto)
                    .addComponent(chkTerminarProyecto)
                    .addComponent(chkVerProyecto)
                    .addComponent(chkEditarProyecto)
                    .addComponent(chkCrearProyecto)
                    .addComponent(jLabel3))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkCrearProyecto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkEditarProyecto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkVerProyecto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkTerminarProyecto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkInformeProyecto)
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        chkCrearPT.setText("Crear");

        chkVerPT.setText("Ver");

        chkEditarPT.setText("Editar");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel6.setText("Papel de Trabajo");

        chkVistaPrePT.setText("Vista preliminar");

        chkCompletarPT.setText("Completar");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(chkVistaPrePT)
                    .addComponent(chkCompletarPT)
                    .addComponent(chkVerPT)
                    .addComponent(chkEditarPT)
                    .addComponent(chkCrearPT)
                    .addComponent(jLabel6))
                .addContainerGap(27, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkCrearPT)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkEditarPT)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkVerPT)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
                .addComponent(chkCompletarPT)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkVistaPrePT)
                .addGap(12, 12, 12))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        chkCrearHallazgo.setText("Crear");

        chkVerHallazgo.setText("Ver");

        chkEditarHallazgo.setText("Editar");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel5.setText("Hallazgo");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(chkVerHallazgo)
                    .addComponent(chkEditarHallazgo)
                    .addComponent(chkCrearHallazgo)
                    .addComponent(jLabel5))
                .addContainerGap(79, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkCrearHallazgo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkEditarHallazgo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkVerHallazgo)
                .addContainerGap(67, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        chkCrearUsuario.setText("Crear");

        chkVerUsuario.setText("Ver");

        chkEditarUsuario.setText("Editar");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel7.setText("Usuario");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(15, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(chkVerUsuario)
                    .addComponent(chkEditarUsuario)
                    .addComponent(chkCrearUsuario)
                    .addComponent(jLabel7))
                .addGap(84, 84, 84))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkCrearUsuario)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkEditarUsuario)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkVerUsuario)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        chkCrearPerfil.setText("Crear");

        chkVerPerfil.setText("Ver");

        chkEditarPerfil.setText("Editar");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel8.setText("Perfil");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(chkVerPerfil)
                    .addComponent(chkEditarPerfil)
                    .addComponent(chkCrearPerfil)
                    .addComponent(jLabel8))
                .addGap(84, 84, 84))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkCrearPerfil)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkEditarPerfil)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkVerPerfil)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jPanel8.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        chkLogs.setText("Auditoría");

        chkReportePortafolio.setText("Estado de Portafolio");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel9.setText("Reportes");

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(chkReportePortafolio)
                    .addComponent(chkLogs)
                    .addComponent(jLabel9))
                .addContainerGap(14, Short.MAX_VALUE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkLogs)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkReportePortafolio)
                .addContainerGap(47, Short.MAX_VALUE))
        );

        jPanel9.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        chkCrearRecomendacion.setText("Crear");

        chkVerRecomendacion.setText("Ver");

        chkEditarRecomendacion.setText("Editar");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel10.setText("Recomendación");

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(chkVerRecomendacion)
                    .addComponent(chkEditarRecomendacion)
                    .addComponent(chkCrearRecomendacion)
                    .addComponent(jLabel10))
                .addContainerGap(41, Short.MAX_VALUE))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkCrearRecomendacion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkEditarRecomendacion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkVerRecomendacion)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );

        btnLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/AdministracionPlantillas/limpiar.png"))); // NOI18N
        btnLimpiar.setText("Limpiar");
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        btnCancelar3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/AdministracionPlantillas/cancelar.png"))); // NOI18N
        btnCancelar3.setText("Cancelar");
        btnCancelar3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelar3ActionPerformed(evt);
            }
        });

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/AdministracionPlantillas/guardar.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/AdministracionPlantillas/edit.gif"))); // NOI18N
        btnEditar.setText("Editar");
        btnEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarActionPerformed(evt);
            }
        });

        jLabel2.setText("Descripción:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(28, 28, 28)
                                .addComponent(txtDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 437, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 437, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(32, Short.MAX_VALUE)
                .addComponent(btnEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addComponent(btnCancelar3, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(31, 31, 31)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnEditar)
                    .addComponent(btnGuardar)
                    .addComponent(btnLimpiar)
                    .addComponent(btnCancelar3))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
    guardar();
}//GEN-LAST:event_btnGuardarActionPerformed

private void btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed
    modoVentana = Principal.MODO_EDICION;
    setearModo();
}//GEN-LAST:event_btnEditarActionPerformed

private void btnCancelar3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelar3ActionPerformed
    limpiar();
    regresarMantPerfiles();
}//GEN-LAST:event_btnCancelar3ActionPerformed

private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
    limpiar();
}//GEN-LAST:event_btnLimpiarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar3;
    private javax.swing.JButton btnEditar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JCheckBox chkCompletarPT;
    private javax.swing.JCheckBox chkCrearHallazgo;
    private javax.swing.JCheckBox chkCrearMarco;
    private javax.swing.JCheckBox chkCrearPT;
    private javax.swing.JCheckBox chkCrearPerfil;
    private javax.swing.JCheckBox chkCrearProyecto;
    private javax.swing.JCheckBox chkCrearRecomendacion;
    private javax.swing.JCheckBox chkCrearUsuario;
    private javax.swing.JCheckBox chkEditarHallazgo;
    private javax.swing.JCheckBox chkEditarMarco;
    private javax.swing.JCheckBox chkEditarPT;
    private javax.swing.JCheckBox chkEditarPerfil;
    private javax.swing.JCheckBox chkEditarProyecto;
    private javax.swing.JCheckBox chkEditarRecomendacion;
    private javax.swing.JCheckBox chkEditarUsuario;
    private javax.swing.JCheckBox chkInformeProyecto;
    private javax.swing.JCheckBox chkLogs;
    private javax.swing.JCheckBox chkReportePortafolio;
    private javax.swing.JCheckBox chkTerminarProyecto;
    private javax.swing.JCheckBox chkVerHallazgo;
    private javax.swing.JCheckBox chkVerMarco;
    private javax.swing.JCheckBox chkVerPT;
    private javax.swing.JCheckBox chkVerPerfil;
    private javax.swing.JCheckBox chkVerProyecto;
    private javax.swing.JCheckBox chkVerRecomendacion;
    private javax.swing.JCheckBox chkVerUsuario;
    private javax.swing.JCheckBox chkVistaPrePT;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JTextField txtDescripcion;
    private javax.swing.JTextField txtNombre;
    // End of variables declaration//GEN-END:variables

    private void guardar(){
        perfil = new Perfil();
        if (validarCampos()){
            perfil.setNombre(txtNombre.getText().trim());
            perfil.setDescripcion(txtDescripcion.getText().trim());
            int idPerfil = new PerfilBl().guardar(perfil);
            perfil.setIdPerfil(idPerfil);
            guardarPermisosMarcoReferencia();
            guardarPermisosPapelTrabajo();
            guardarPermisosHallazgo();
            guardarPermisosRecomendacion();
            guardarPermisosUsuario();
            guardarPermisoPerfil();
            guardarPermisoLogs();
            guardarPermisoEstadoPortafolio();
            guardarPermisoProyecto();
            if (idPerfil>0) JOptionPane.showMessageDialog(this, "Se ha guardado el enunciado", "Confirmación", JOptionPane.INFORMATION_MESSAGE);
            else JOptionPane.showMessageDialog(this, "Ha ocurrido un error en la grabación", "Error", JOptionPane.ERROR_MESSAGE);                
        }                
    }
    
    private void guardarPermisosMarcoReferencia(){
        String tipoPermiso = "";
        tipoPermiso+=chkCrearMarco.isSelected()?UtilUsuarios.CREAR:"";
        tipoPermiso+=chkEditarMarco.isSelected()?UtilUsuarios.EDITAR:"";
        tipoPermiso+=chkVerMarco.isSelected()?UtilUsuarios.VER:"";        
        FuncionalidadXPerfil fxp = new FuncionalidadXPerfil();
        fxp.setId(new FuncionalidadXPerfilId(UtilUsuarios.MARCO_REFERENCIA, perfil.getIdPerfil()));
        fxp.setTipoPermiso(tipoPermiso);
        if (!tipoPermiso.isEmpty()) new PerfilBl().guardarFuncionalidades(fxp);
    }
    
    private void guardarPermisosPapelTrabajo(){
        String tipoPermiso = "";
        tipoPermiso+=chkCrearPT.isSelected()?UtilUsuarios.CREAR:"";
        tipoPermiso+=chkEditarPT.isSelected()?UtilUsuarios.EDITAR:"";
        tipoPermiso+=chkVerPT.isSelected()?UtilUsuarios.VER:"";        
        tipoPermiso+=chkCompletarPT.isSelected()?UtilUsuarios.COMPLETAR:"";        
        tipoPermiso+=chkVistaPrePT.isSelected()?UtilUsuarios.GENERAR_INFORME:"";        
        FuncionalidadXPerfil fxp = new FuncionalidadXPerfil();
        fxp.setId(new FuncionalidadXPerfilId(UtilUsuarios.MARCO_REFERENCIA, perfil.getIdPerfil()));
        fxp.setTipoPermiso(tipoPermiso);
        if (!tipoPermiso.isEmpty()) new PerfilBl().guardarFuncionalidades(fxp);
    }
    
    private void guardarPermisosHallazgo(){
        String tipoPermiso = "";
        tipoPermiso+=chkCrearHallazgo.isSelected()?UtilUsuarios.CREAR:"";
        tipoPermiso+=chkEditarHallazgo.isSelected()?UtilUsuarios.EDITAR:"";
        tipoPermiso+=chkVerHallazgo.isSelected()?UtilUsuarios.VER:"";        
        FuncionalidadXPerfil fxp = new FuncionalidadXPerfil();
        fxp.setId(new FuncionalidadXPerfilId(UtilUsuarios.HALLAZGO, perfil.getIdPerfil()));
        fxp.setTipoPermiso(tipoPermiso);
        if (!tipoPermiso.isEmpty()) new PerfilBl().guardarFuncionalidades(fxp);
    }
    
    private void guardarPermisosRecomendacion(){
        String tipoPermiso = "";
        tipoPermiso+=chkCrearRecomendacion.isSelected()?UtilUsuarios.CREAR:"";
        tipoPermiso+=chkEditarRecomendacion.isSelected()?UtilUsuarios.EDITAR:"";
        tipoPermiso+=chkVerRecomendacion.isSelected()?UtilUsuarios.VER:"";        
        FuncionalidadXPerfil fxp = new FuncionalidadXPerfil();
        fxp.setId(new FuncionalidadXPerfilId(UtilUsuarios.RECOMENDACION, perfil.getIdPerfil()));
        fxp.setTipoPermiso(tipoPermiso);
        if (!tipoPermiso.isEmpty()) new PerfilBl().guardarFuncionalidades(fxp);
    }
    
    private void guardarPermisosUsuario(){
        String tipoPermiso = "";
        tipoPermiso+=chkCrearUsuario.isSelected()?UtilUsuarios.CREAR:"";
        tipoPermiso+=chkEditarUsuario.isSelected()?UtilUsuarios.EDITAR:"";
        tipoPermiso+=chkVerUsuario.isSelected()?UtilUsuarios.VER:"";        
        FuncionalidadXPerfil fxp = new FuncionalidadXPerfil();
        fxp.setId(new FuncionalidadXPerfilId(UtilUsuarios.USUARIO, perfil.getIdPerfil()));
        fxp.setTipoPermiso(tipoPermiso);
        if (!tipoPermiso.isEmpty()) new PerfilBl().guardarFuncionalidades(fxp);
    }
    
    private void guardarPermisoPerfil(){
        String tipoPermiso = "";
        tipoPermiso+=chkCrearPerfil.isSelected()?UtilUsuarios.CREAR:"";
        tipoPermiso+=chkEditarPerfil.isSelected()?UtilUsuarios.EDITAR:"";
        tipoPermiso+=chkVerPerfil.isSelected()?UtilUsuarios.VER:"";        
        FuncionalidadXPerfil fxp = new FuncionalidadXPerfil();
        fxp.setId(new FuncionalidadXPerfilId(UtilUsuarios.PERFIL, perfil.getIdPerfil()));
        fxp.setTipoPermiso(tipoPermiso);
        if (!tipoPermiso.isEmpty()) new PerfilBl().guardarFuncionalidades(fxp);
    }
    
    private void guardarPermisoLogs(){
        FuncionalidadXPerfil fxp = new FuncionalidadXPerfil();
        fxp.setId(new FuncionalidadXPerfilId(UtilUsuarios.PERFIL, perfil.getIdPerfil()));
        fxp.setTipoPermiso(chkLogs.isSelected()?"v":"");
        if (!fxp.getTipoPermiso().isEmpty()) new PerfilBl().guardarFuncionalidades(fxp);
    }
    
    private void guardarPermisoEstadoPortafolio(){
        FuncionalidadXPerfil fxp = new FuncionalidadXPerfil();
        fxp.setId(new FuncionalidadXPerfilId(UtilUsuarios.REPORTE_PORTAFOLIO, perfil.getIdPerfil()));
        fxp.setTipoPermiso(chkReportePortafolio.isSelected()?"c":"");
        if (!fxp.getTipoPermiso().isEmpty()) new PerfilBl().guardarFuncionalidades(fxp);
    }
    
    private void guardarPermisoProyecto(){
        String tipoPermiso = "";
        tipoPermiso+=chkCrearProyecto.isSelected()?UtilUsuarios.CREAR:"";
        tipoPermiso+=chkEditarProyecto.isSelected()?UtilUsuarios.EDITAR:"";
        tipoPermiso+=chkVerProyecto.isSelected()?UtilUsuarios.VER:"";        
        tipoPermiso+=chkTerminarProyecto.isSelected()?UtilUsuarios.COMPLETAR:"";
        tipoPermiso+=chkInformeProyecto.isSelected()?UtilUsuarios.GENERAR_INFORME:"";       
        FuncionalidadXPerfil fxp = new FuncionalidadXPerfil();
        fxp.setId(new FuncionalidadXPerfilId(UtilUsuarios.PROYECTO, perfil.getIdPerfil()));
        fxp.setTipoPermiso(tipoPermiso);
         if (!tipoPermiso.isEmpty()) new PerfilBl().guardarFuncionalidades(fxp);    
    }
    
    private boolean validarCampos(){
        return true;
    }

    /**
     * @param ventanaPrincipal the ventanaPrincipal to set
     */
    public void setVentanaPrincipal(Principal ventanaPrincipal) {
        this.ventanaPrincipal = ventanaPrincipal;
        bloquearPorPermisos();
    }

    private void limpiar() {
        
    }
    
    private void mostrarMenuOpciones(){
        ventanaPrincipal.panelUsuarios.menuOpciones.setVisible(true);        
        ventanaPrincipal.panelUsuarios.remove(this);
    }

    private void regresarMantPerfiles() {
        ventanaPrincipal.panelUsuarios.add(ventanaPrincipal.panelUsuarios.mantPerfiles);
        ventanaPrincipal.panelUsuarios.mantPerfiles.buscarPerfiles();
        ventanaPrincipal.panelUsuarios.mantPerfiles.setVisible(true);        
        ventanaPrincipal.panelUsuarios.remove(this);
    }

    private void bloquearPorPermisos() {               
        if (ventanaPrincipal.getPermisos().getPermisoPerfil().indexOf(UtilUsuarios.VER)>-1){
            btnEditar.setVisible(false);
            btnEditar.setEnabled(false);
            btnGuardar.setVisible(false);
            btnGuardar.setEnabled(false);
        }        
        if (ventanaPrincipal.getPermisos().getPermisoPerfil().indexOf(UtilUsuarios.CREAR)>-1){
            btnEditar.setVisible(false);
            btnEditar.setEnabled(false);
            btnGuardar.setVisible(true);
            btnGuardar.setEnabled(true);
        }                
        if (ventanaPrincipal.getPermisos().getPermisoPerfil().indexOf(UtilUsuarios.EDITAR)>-1){
            btnEditar.setVisible(true);
            btnEditar.setEnabled(true);
            btnGuardar.setVisible(true);
            btnGuardar.setEnabled(true);
        }        
    }

}
